﻿    function gotFocus(invoiceAmount1) {
        //var invoiceAmount1 = document.getElementById("<%=txtInvoiceAmount1.ClientID%>");
        
        invoiceAmount1.value = removeCommas(invoiceAmount1.value);
    }
    
    
    function lostFocus(invoiceAmount1) {
        //var invoiceAmount1 = document.getElementById("<%=txtInvoiceAmount1.ClientID%>");
        
        invoiceAmount1.value = addCommas(invoiceAmount1.value);
    }
    
    
    function addCommas(nStr)
    {
        if (nStr == '') {
            return '0'
        }
        
        nStr += '';
        x = nStr.split('.');
        x1 = x[0];
        x2 = x.length > 1 ? '.' + x[1] : '';
        var rgx = /(\d+)(\d{3})/;
        while (rgx.test(x1)) {
	        x1 = x1.replace(rgx, '$1' + ',' + '$2');
        }
        return x1 + x2;
    }
    
    
    function removeCommas(nStr)
    {
	    nStr = xreplace(nStr, ',', '') ;
	    return nStr;
    }
    
    
    function xreplace(checkMe,toberep,repwith)
    { 
    	temp = checkMe;
    	a = 0;


        for(i = 0; i < checkMe.length; i++){
            a = temp.indexOf(toberep);
            temp = temp.substring(0 , a) + repwith + temp.substring((a + toberep.length));


            if (a == -1){
                break;
            }
    	}
    	return temp;
    }
    
    function checkDecimal (txtPercent) {
        var k = event.keyCode
        if ((k >= 48) && (k <= 57) || k == 46 || k == 8) {
            if (inStr(0, txtPercent.value, '.') > 0) {
                if (k == 46) {
                    return false;
                }
            }
        } else
            return false;
    }
    
    